//
//  CQEffectViewFactory.m
//  AppCommonUICollect
//
//  Created by ciyouzen on 2019/8/13.
//  Copyright © 2019 dvlproad. All rights reserved.
//

#import "CQEffectViewFactory.h"

@implementation CQEffectViewFactory

+ (UIColor *)cqCustom_selfBottom_blankBGColor {
    UIColor *blankBGColor = [UIColor colorWithRed:17/255.0 green:17/255.0 blue:17/255.0 alpha:.8];
    return blankBGColor;
}

+ (UIColor *)cqCustom_selfCenter_blankBGColor {
    UIColor *blankBGColor = [UIColor colorWithRed:17/255.0 green:17/255.0 blue:17/255.0 alpha:.8];
    return blankBGColor;
}


/*
 *  添加effectView紧靠effectForView
 *
 *  @param effectType       effectType
 *  @param toSuperview      添加到哪个视图里(注意：请确保toSuperview包含或者至少等于effectForView)
 *  @param effectForView    和哪个视图紧靠/给哪个视图所在的区域添加效果
 */
+ (UIVisualEffectView *)addEffectwithEffectType:(UIBlurEffectStyle)effectType toView:(UIView *)toSuperview closeView:(UIView *)effectForView {
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:effectType];
    
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    
    [self __addEffectView:effectView toView:toSuperview closeView:effectForView];
    
    return effectView;
}

/*
 *  添加effectView紧靠effectForView
 *
 *  @param effectView       要添加的效果视图
 *  @param toSuperview      添加到哪个视图里(注意：请确保toSuperview包含或者至少等于effectForView)
 *  @param effectForView    和哪个视图紧靠/给哪个视图所在的区域添加效果
 */
+ (void)__addEffectView:(UIVisualEffectView *)effectView toView:(UIView *)toSuperview closeView:(UIView *)effectForView {
    [toSuperview addSubview:effectView];
    [toSuperview sendSubviewToBack:effectView];   // popupView已经改成添加到blankView中了
    effectView.translatesAutoresizingMaskIntoConstraints = NO;
    
    [toSuperview addConstraint:
     [NSLayoutConstraint constraintWithItem:effectView
                                  attribute:NSLayoutAttributeLeft   //left
                                  relatedBy:NSLayoutRelationEqual
                                     toItem:effectForView
                                  attribute:NSLayoutAttributeLeft
                                 multiplier:1
                                   constant:0]];
    
    [toSuperview addConstraint:
     [NSLayoutConstraint constraintWithItem:effectView
                                  attribute:NSLayoutAttributeRight  //right
                                  relatedBy:NSLayoutRelationEqual
                                     toItem:effectForView
                                  attribute:NSLayoutAttributeRight
                                 multiplier:1
                                   constant:0]];
    
    [toSuperview addConstraint:
     [NSLayoutConstraint constraintWithItem:effectView
                                  attribute:NSLayoutAttributeTop    //top
                                  relatedBy:NSLayoutRelationEqual
                                     toItem:effectForView
                                  attribute:NSLayoutAttributeTop
                                 multiplier:1
                                   constant:0]];
    
    [toSuperview addConstraint:
     [NSLayoutConstraint constraintWithItem:effectView
                                  attribute:NSLayoutAttributeBottom //bottom
                                  relatedBy:NSLayoutRelationEqual
                                     toItem:effectForView
                                  attribute:NSLayoutAttributeBottom
                                 multiplier:1
                                   constant:0]];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
